package com.jkc.xh.adapters;

import android.view.View;
import android.view.ViewGroup;

import com.jkc.xh.R;
import com.jkc.xh.adapters.core.BaseRecyclerAdapter;
import com.jkc.xh.adapters.viewholder.MyFactoryHoldAllItemView;
import com.jkc.xh.adapters.viewholder.MyFactoryHoldAllItemView_;
import com.jkc.xh.models.HoldAllModel;

/**
 * Created by macintosh on 15/11/17.
 */
public class MyFactoryHoldAllAdapter extends BaseRecyclerAdapter<HoldAllModel, MyFactoryHoldAllItemView> implements BaseRecyclerAdapter.OnItemClickListener {
    private View currentView = null;

    @Override
    protected void onBindView(MyFactoryHoldAllItemView itemView, HoldAllModel orderModel, int position) {
        itemView.bind(orderModel);
    }

    @Override
    protected MyFactoryHoldAllItemView onCreateItemView(ViewGroup parent, int viewType) {
        return MyFactoryHoldAllItemView_.build(parent.getContext());
    }

    public void setListener(OnViewClickListener listener) {
        addOnViewClickListener(R.id.btnSold, listener);
    }

    @Override
    public void onItemClick(View view, Object object, int position) {
        if (currentView == null) {
            currentView = view;
        } else {
            if (currentView == view) {
                ((MyFactoryHoldAllItemView) currentView).disableMoreOption();
                currentView = null;
                return;
            }
            ((MyFactoryHoldAllItemView) currentView).disableMoreOption();
            currentView = view;
        }
        ((MyFactoryHoldAllItemView) currentView).showMoreOption();
    }
}
